package com.bawei.module_home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_home.R
import com.bawei.module_home.databinding.HourseItemBinding
import com.bawei.module_home.databinding.HouseItem2Binding
import com.bawei.module_home.model.HouseItem

class HouseAdapter2: RecyclerView.Adapter<HouseAdapter2.HouseViewHolder>() {
    val houseList2= mutableListOf<HouseItem>()
    fun setData(data:List<HouseItem>){
        houseList2.clear()
        houseList2.addAll(data)
        notifyDataSetChanged()
    }




    class HouseViewHolder(item:HouseItem2Binding):RecyclerView.ViewHolder(item.root){}

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HouseViewHolder {
        val binding = DataBindingUtil.inflate<HouseItem2Binding>(
            LayoutInflater.from(parent.context),
            R.layout.house_item2,
            parent,
            false
        )
        return HouseViewHolder(binding)
    }

    override fun getItemCount(): Int {
      return houseList2.size
    }

    override fun onBindViewHolder(holder: HouseViewHolder, position: Int) {
        val binding=DataBindingUtil.getBinding<HouseItem2Binding>(holder.itemView)
        binding?.house2Number?.setText(houseList2[position].regionId.toString()+ "室 ")
        if (houseList2[position].rented==true){
            binding?.house2Status?.setText("已租")
            binding?.house2Status?.setBackgroundResource(R.drawable.bg_status_rented)


        }else{
            binding?.house2Status?.setText("出租")
            binding?.house2Status?.setBackgroundResource(R.drawable.bg_status_rent)

        }

        binding?.houseCompany?.setText("企业："+houseList2[position].enterpriseName)
        binding?.house2Area?.setText("面积："+houseList2[position].area+"m2")



        }







    }




